package main

import (
	"fmt"
	"sync"
	"time"
)

func main() {
	var ch = make(chan int, 8)
	var wg = new(sync.WaitGroup)
	// 写
	for i := 1; i <= 4; i++ {
		wg.Add(1)
		go func(num int, ch chan<- int, wg *sync.WaitGroup) {
			defer wg.Done()
			ch <- num
			ch <- num * 10
		}(i, ch, wg)
	}
	// 读
	go func(ch <-chan int) {
		for num := range ch {
			fmt.Println(num)
		}
	}(ch)
	wg.Wait()
	close(ch)
	time.Sleep(time.Second)
	fmt.Println("finish")
}
